//测试vscode如何提交项目修改文件到码云
const path = require('path');
const express = require('express');
const session=require("express-session");
const bodyParser = require('body-parser');
const ejs = require('ejs');
const favicon = require('serve-favicon');
const tracer = require('tracer').colorConsole();
const app = express();
const multer  = require('multer');//用express的第三方中间件 multer 实现文件上传功能。
const fs = require('fs')


//声明静态文件
app.use(session({
    secret: 'hubwiz app', //secret的值建议使用随机字符串
    name: 'testapp',
    cookie: {maxAge: 60 * 1000 * 30}, // 过期时间（毫秒）
    saveUninitialized: false, // 是否自动保存未初始化的会话，建议false
    resave: true // 是否每次都重新保存会话，建议false
}));

//路由
var BackStage = require('./routes/BackStage/index');//引入路由
var HR = require('./routes/BackStage/HR');//引入路由
var message = require('./routes/BackStage/message');//引入路由
var menu = require('./routes/BackStage/menu');//引入路由
var login = require('./routes/BackStage/login');//引入路由
var role = require('./routes/BackStage/role');//引入路由
var fuction = require('./routes/BackStage/function');//引入路由
var jurisdiction = require('./routes/BackStage/jurisdiction');//引入路由


/**************后台网站*************** */


/**************路由别名*************** */
app.use('/BackStage',BackStage);
app.use('/login',login);
app.use('/HR',HR);
app.use('/message',message);
app.use('/menu',menu);
app.use('/role',role);
app.use('/function',fuction);
app.use('/jurisdiction',jurisdiction);

/**
 * 跳转后台登陆路由中的方法
 */ 


app.use(express.static(path.join(__dirname, 'templates'))); //声明templates为外部可用地址 正常存放 js img css

var upload = multer({dest:'./templates/BackStage/image'});




app.get('/',function(req,res){
    res.redirect("/BackStage/");
});


app.set('views', path.join(__dirname, 'templates'));  //声明模板路径。
app.engine('html', ejs.renderFile);//引擎模板
app.set('view engine', 'html'); //模板后缀
app.set('view cache', false); //不启用模板缓存




//处理页面数据 
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());


//网页图标
app.use(favicon('templates/assets/image/car.ico'));

tracer.info('服务已启动', `http://127.0.0.1:8000`);


app.listen(8000);